package org.zhxy.common.base;

import org.apache.shiro.SecurityUtils;
import org.zhxy.common.response.ProfileResult;
import org.zhxy.common.utils.Constants;
import org.zhxy.entity.system.User;

import java.util.Map;

public class BaseService {

    public static User currentUser(){
        ProfileResult profileResult = (ProfileResult) SecurityUtils.getSubject().getPrincipal();
        return profileResult.getUser();
    }

    public static Map<String, Object> currentMap(Map<String, Object> map){
        map.put("id",currentUser().getId());

        if(map.get(Constants.Blanket.PAGE) != null && map.get(Constants.Blanket.SIZE) != null ){
            map.put(Constants.Blanket.PAGE,(Integer.parseInt(map.get(Constants.Blanket.PAGE).toString()) - Constants.Number.ONE) *
                    Integer.parseInt(map.get(Constants.Blanket.SIZE).toString()));
            map.put(Constants.Blanket.SIZE,Integer.parseInt(map.get(Constants.Blanket.SIZE).toString()));
        }

        return map;
    }
}
